'''Interface of the map_to_xml module'''
import re

from os import listdir
from os.path import isfile, join, splitext

import gcc_parser
import diab_parser

def supportedMapTypes():
    '''Fetch a list of supported mapfile types (compilers)'''
    supported = []
    regex = re.compile(r"(\w+)_parser")
    path = "map_to_xml"
    for item in listdir("map_to_xml"):
        if(isfile(join(path, item))):
            if(splitext(item)[1] == ".py"):
                if(splitext(item)[1] == ".py"):
                    match = regex.findall(splitext(item)[0])
                    if match:
                        supported.append(match[0])
    return supported

def convert_map_to_xml(mapfile, xmlfile, maptype):
    '''Convert a given mapfile with a given format to a predetermined xml format and write the output to a given file'''
    if maptype is 'GCC':
        gcc_parser.parse_gcc(mapfile, xmlfile)
    if maptype is 'DIAB':
        diab_parser.parse_diab(mapfile, xmlfile)

